package com.hj.demo;

import java.util.Arrays;

public class Demo2 {
    public static void main(String[] args) {
        Demo2FuImpl demo2FuImpl = new Demo2FuImpl();
        int[] arr={1,2,3,4,5,6,7,8,9,10};
        String[] arr1=new String[5];
        demo2FuImpl.finAll(arr);
        demo2FuImpl.address(arr,5);
        demo2FuImpl.diverse(arr);
        demo2FuImpl.deleteIndex(arr,5);
        demo2FuImpl.addIndex(arr,5,100);
        demo2FuImpl.yuanSuMax(arr1);
    }
}
abstract class Demo2Fu {
    public abstract void finAll(int[] arr);
    public abstract void address(int[] arr,int num);
    public abstract void diverse(int[] arr);
    public abstract void deleteIndex(int[] arr,int index);
    public abstract void addIndex(int[] arr,int index,int num);
    public abstract void yuanSuMax(String[] arr);
}
class Demo2FuImpl extends Demo2Fu{
    @Override
    public void finAll(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++){
            if (i< arr.length-1){
                System.out.print(arr[i]+", ");
            }else {
                System.out.print(arr[i]);
            }
        }
        System.out.println("]");
        System.out.println();
    }

    @Override
    public void address(int[] arr,int num) {
        int index=-1;
        for (int i = 0; i < arr.length; i++) {
            if (num==arr[i]){
                index=i;
                break;
            }
        }
        if (index!=-1){
            System.out.println("index："+index);
        }else{
            System.out.println("元素不存在");
        }
        System.out.println();
    }

    @Override
    public void diverse(int[] arr) {
        int[] brr=new int[arr.length];
        for (int i = arr.length - 1,j=0; i >= 0; i--,j++) {
            brr[j]=arr[i];
        }
        System.out.println(Arrays.toString(brr));
        System.out.println();
    }

    @Override
    public void deleteIndex(int[] arr, int index) {
        int[] brr=new int[arr.length-1];
        for (int i = 0,j=0; i < arr.length; i++) {
            if (i==index){
                continue;
            }
            brr[j]=arr[i];
            j++;
        }
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(brr));
        System.out.println();
    }

    @Override
    public void addIndex(int[] arr, int index,int num) {
        int[] brr=new int[arr.length+1];
        for (int i = 0,j=0; i < brr.length; i++) {
            if (i==index){
                brr[i]=num;
                continue;
            }
            brr[i]=arr[j];
            j++;
        }
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(brr));
        System.out.println();
    }

    @Override
    public void yuanSuMax(String[] arr) {
        boolean len =true;
        for (String s : arr) {
            if (s == null) {
                len = false;
                break;
            }
        }
        if (len){
            System.out.println("已满");
        }else {
            System.out.println("未满");
        }
    }
}